<?php

namespace App\Logging;

use Psr\Log\LoggerInterface;

abstract class CreateCustomLogger implements LoggerInterface
{
    protected array $config = [];

    public function __construct(array $config = [])
    {
        $this->config = $config;
    }

    abstract protected function write(string $message, array $context = []);

    public function __invoke(array $config)
    {
        return new static($config);
    }

    public function emergency($message, array $context = []): void
    {
        $this->write($message, $context);
    }

    public function alert($message, array $context = []): void
    {
        $this->write($message, $context);
    }

    public function critical($message, array $context = []): void
    {
        $this->write($message, $context);
    }

    public function error($message, array $context = []): void
    {
        $this->write($message, $context);
    }

    public function warning($message, array $context = []): void
    {
        $this->write($message, $context);
    }

    public function notice($message, array $context = []): void
    {
        $this->write($message, $context);
    }

    public function info($message, array $context = []): void
    {
        $this->write($message, $context);
    }

    public function debug($message, array $context = []): void
    {
        $this->write($message, $context);
    }

    public function log($level, $message, array $context = []): void
    {
        if (in_array($level, ['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'])) {
            $this->$level($message, $context);
        } else {
            $this->error($message, $context);
        }
    }
}
